<?php

 class ForumAction extends CommonAction{
 	
 	/**
 	 * 帖子 列表
 	 * Enter description here ...
 	 */
 	function index(){

 		import('ORG.Util.Page');

 		$count=M('Forum')->count();// 查询总数据记录

 		$Page = new Page($count,C('PAGESIZE'));

 		$show= $Page->show();

 		$list = M('Forum')->order("createtime DESC")->limit($Page->firstRow.','.$Page->listRows)->select();

 		 

 		$this->assign("list",$list);

 		$this->assign("page",$show);

 		$this->display();
 			
 			
 	}
 	/**
 	 * 添加帖子
 	 * Enter description here ...
 	 */
 	function add(){
 		if(isset($_POST['submit'])){
 		  $data = $_POST;
 		  $data['createtime']= mktime();
 		  if(M('Forum')->add($data)){
 		  	
 		  	$this->success("添加帖子成功！",U('index'));
 		  }	 
 		}else{
 			$this->list =M('ForumCate')->select();
 			$this->display();
 		}
 		
 	}
 	
 	
 	function edit(){
 		$id = is_numeric($_GET['id'])?$_GET['id']:exit();
 		if(isset($_POST['submit'])){
 			 $data = $_POST;
 			 $data['createtime']= mktime();
 			 M('Forum')->where("id=".$id)->save($data);
 			 $this->success("编辑信息成功！",U('index'));
 		}else{
 			$this->li =M('Forum')->where("id=".$id)->find();
 			$this->list =M('ForumCate')->select();
 			$this->display();
 		}
 		
 	}
 	
 	/**
 	 * 帖子分类
 	 * Enter description here ...
 	 */
 	function cate(){
 		 
 		$this->list =M('ForumCate')->select();
 		$this->display();
 		
 	}
 	/**
 	 * 添加分类
 	 * Enter description here ...
 	 */
 	function addcate(){
 		if(isset($_POST['submit'])){
 			 if(M('ForumCate')->add($_POST)){
 			 	
 			 	$this->success("添加论坛分类成功",U('cate'));
 			 } 
 			
 		}else{
 			
 			$this->display();
 		}
 		
 	}
 	/**
 	 * 编辑分类
 	 * Enter description here ...
 	 */
 	function editcate(){
 		$id = is_numeric($_GET['id'])?$_GET['id']:exit();
 		if(isset($_POST['submit'])){
 			 M('FroumCate')->where("id=".$id)->save($_POST);
 			$this->success("更新分类成功！",U('cate'));
 		}else{
 			$this->li =M('ForumCate')->where("id=".$id)->find();
 			$this->display();
 		}
 		
 	}
 	
 	function delcate(){
 		$id = is_numeric($_GET['id'])?$_GET['id']:exit();
 		M('ForumCate')->where("id=".$id)->delete();
 		$this->success("删除成功！");
 	}
 	
 }
?>